<template>
	<view class="detailed">
		<view class="detailed_title">
			<view class="detailed_title_list" :style="{width:width}" v-for="(item,index) in titleList" :key="index">
				{{item}}
			</view>
		</view>
		<view class="detailed_content">
			<scroll-view scroll-y="true" class="scroll-Y">
				<u-empty mode="history" icon="http://cdn.uviewui.com/uview/empty/history.png" v-if="contentList.length==0"
					marginTop="100px" text="暂无记录">
				</u-empty>
				<view class="detailed_content_list" v-for="(item,index) in contentList" :key="index"
					@click="more(item)">
					<view :style="{width:width}" class="time">
						{{item.createTime}}
					</view>
					<view :style="{width:width}" :class="item.typeId==1?'red':'green'" v-if="item.balanceTypeId!=8">
						{{item.typeId==1?'收入':'支出'}}
					</view>
					<view :style="{width:width}" class="tuihui" v-else>
						退回
					</view>
					<view :style="{width:width}">
						{{item.balance}}
					</view>
					<view :style="{width:width}">
						{{item.profit}}
					</view>
					<view :style="{width:width}" v-if="type==0">
						{{item.accountType==1?'认养券':item.accountType==2?'鸡蛋':item.accountType==3?'健康分':item.accountType==4?'消费券':item.accountType==5?'股权':item.accountType==8?'积分':'余额'}}
					</view>
				</view>
			</scroll-view>
		</view>
		<span class="detailed_footer" v-if="type==5">股权余额：{{price.stockRight}}</span>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleList: [],
				price: {},
				contentList: [],
				type: 0,
				width: "20%"
			}
		},
		onLoad(option) {
			this.type = option.type
			if (option.type == 0) {
				this.titleList = ["日期", "类型", "金额", "余额", "货币类型"]
				this.width = "20%"
			} else {
				this.titleList = ["日期", "类型", "金额", "余额"]
				this.width = "25%"
			}
			this.$http({
				url: '/crmAccount/selMemberCrmAccount',
				method: 'GET',
				data: {
					type: option.type
				}
			}).then(res => {
				if (res.data.code === 200) {
					this.contentList = res.data.data
					this.contentList.map(item => {
						item.createTime = this.dateArrayTransfer(item.createTime)
					})
				}
			})
		},
		onShow() {
			// 查询各类余额
			this.$http({
				url: '/member/getMemberAccount',
			}).then(res => {
				if (res.data.code === 200) {
					this.price = res.data.data
				} else {
					this.price = {}
				}
			})
		},
		methods: {
			more(e) {
				//账单详情
				uni.navigateTo({
					url: '/pages/detailedmore/detailedmore?accountType=' + e.accountType + '&balance=' + e
						.balance + '&balanceTypeId=' + e.balanceTypeId + '&createTime=' + e.createTime +
						'&id=' + e.id + '&nickName=' + e.nickName + '&profit=' + e
						.profit + '&remark=' + e.remark + '&serialNumber=' + e.serialNumber +
						'&typeId=' + e.typeId + '&uid=' + e.uid
				})
			},
			dateArrayTransfer(dateArray) {
				if (dateArray == null || dateArray == '') {
					return '无';
				}
				if (dateArray.length == 6) {
					var returnDate = dateArray[0] + "-" +
						this.returnDoubleNum(dateArray[1]) + "-" +
						this.returnDoubleNum(dateArray[2]) + " " +
						this.returnDoubleNum(dateArray[3]) + ":" +
						this.returnDoubleNum(dateArray[4]) + ":" +
						this.returnDoubleNum(dateArray[5]);
				} else {
					var returnDate = dateArray[0] + "-" +
						this.returnDoubleNum(dateArray[1]) + "-" +
						this.returnDoubleNum(dateArray[2]) + " " +
						this.returnDoubleNum(dateArray[3]) + ":" +
						this.returnDoubleNum(dateArray[4]) + ":00";
				}
				return returnDate;
			},
			returnDoubleNum(number) {
				return (Array(2).join(0) + number).slice(-2); //创建一个长度为2的数组，且默认用0填充；然后用传过来的数添加都右边，然后从右向左截取两位！
			},
		},
	}
</script>


<style lang="scss" scoped>
	@import './detailed.css'
</style>
